def is_prime(n):
    if n <= 1:
        return False
    for i in range(2, int(n * 0.5) + 1):
        if n % i == 0:
            return False
    return True
def find_closest_prime(n):
    step = 1
    while True:
        if is_prime(n + step):
            return n + step
        if is_prime(n - step):
            return n - step
        step += 1
word_to_digit = {
    "zero": 0,
    "one": 1,
    "two": 2,
    "three": 3,
    "four": 4,
    "five": 5,
    "six": 6,
    "seven": 7,
    "eight": 8,
    "nine": 9,
}
input_words = input().split()
if len(input_words) != 3:
    print("Wrong input")
else:
    try:
        number = word_to_digit[input_words[0]] * 100 + word_to_digit[input_words[1]] * 10 + word_to_digit[
            input_words[2]]
        if 100 <= number <= 999:
            print(find_closest_prime(number))
        else:
            print('Wronginput')
    except KeyError:
        print("Wrong input")